"""
from sympy import symbols, sqrt, diff, acos


x1, y1, z1, x2, y2, z2 = symbols('x1 y1 z1 x2 y2 z2')

r1 = sqrt(x1*x1 + y1*y1 + z1*z1)
r2 = sqrt(x2*x2 + y2*y2 + z2*z2)

cosa = (x1*x2+y1*y2+z1*z2)/r1/r2

theta = acos(cosa)

v1x = diff(theta, x1)
v1y = diff(theta, y1);
v1z = diff(theta, z1);

v2x = diff(theta, x2)
v2y = diff(theta, y2);
v2z = diff(theta, z2);


print "dx[0].x =", v1x
print "dx[0].y =", v1y
print "dx[0].z =", v1z

print "dx[1].x =", v2x
print "dx[1].y =", v2y
print "dx[1].z =", v2z

print "dx2[0][0][0] =", diff(v1x, x1)
print "dx2[0][0][1] =", diff(v1x, y1)
print "dx2[0][0][2] =", diff(v1x, z1)
print "dx2[0][1][0] =", diff(v1y, x1)
print "dx2[0][1][1] =", diff(v1y, y1)
print "dx2[0][1][2] =", diff(v1y, z1)
print "dx2[0][2][0] =", diff(v1z, x1)
print "dx2[0][2][1] =", diff(v1z, y1)
print "dx2[0][2][2] =", diff(v1z, z1)


print "dx2[1][0][0] = dx2[2][0][0] = ", diff(v1x, x2)
print "dx2[1][0][1] = dx2[2][1][0] = ", diff(v1x, y2)
print "dx2[1][0][2] = dx2[2][2][0] = ", diff(v1x, z2)
print "dx2[1][1][0] = dx2[2][0][1] = ", diff(v1y, x2)
print "dx2[1][1][1] = dx2[2][1][1] = ", diff(v1y, y2)
print "dx2[1][1][2] = dx2[2][2][1] = ", diff(v1y, z2)
print "dx2[1][2][0] = dx2[2][0][2] = ", diff(v1z, x2)
print "dx2[1][2][1] = dx2[2][1][2] = ", diff(v1z, y2)
print "dx2[1][2][2] = dx2[2][2][2] = ", diff(v1z, z2)


print "dx2[3][0][0] =", diff(v2x, x2)
print "dx2[3][0][1] =", diff(v2x, y2)
print "dx2[3][0][2] =", diff(v2x, z2)
print "dx2[3][1][0] =", diff(v2y, x2)
print "dx2[3][1][1] =", diff(v2y, y2)
print "dx2[3][1][2] =", diff(v2y, z2)
print "dx2[3][2][0] =", diff(v2z, x2)
print "dx2[3][2][1] =", diff(v2z, y2)
print "dx2[3][2][2] =", diff(v2z, z2)
"""


from sympy import symbols

nx1, ny1, nz1, nx2, ny2, nz2 = symbols('nx1 ny1 nz1 nx2 ny2 nz2')
r1, r2 = symbols('r1 r2')
sinA, cosA = symbols('sinA cosA')
x1 = r1*nx1
y1 = r1*ny1
z1 = r1*nz1

x2 = r2*nx2
y2 = r2*ny2
z2 = r2*nz2

print "dx[0].x =", -(-x1*cosA/r1**2 + x2/(r1*r2))/sinA
print "dx[0].y =", -(-y1*cosA/r1**2 + y2/(r1*r2))/sinA
print "dx[0].z =", -(-z1*cosA/r1**2 + z2/(r1*r2))/sinA
print "dx[1].x =", -(-x2*cosA/r2**2 + x1/(r1*r2))/sinA
print "dx[1].y =", -(-y2*cosA/r2**2 + y1/(r1*r2))/sinA
print "dx[1].z =", -(-z2*cosA/r2**2 + z1/(r1*r2))/sinA
print "dx2[0][0][0] =", -(-cosA/r1**2 + 3*x1**2*cosA/r1**4 - 2*x1*x2/(r1**3*r2))/sinA - (x2*cosA/r1/r2 - x1*(cosA**2)/(r1**2))*(-x1*cosA/r1**2 + x2/(r1*r2))/(sinA**3)
print "dx2[0][0][1] =", -(3*x1*y1*cosA/r1**4 - x1*y2/(r1**3*r2) - x2*y1/(r1**3*r2))/sinA - (-x1*cosA/r1**2 + x2/(r1*r2))*(y2*cosA/r1/r2 - y1*(cosA**2)/(r1**2))/(sinA**3)
print "dx2[0][0][2] =", -(3*x1*z1*cosA/r1**4 - x1*z2/(r1**3*r2) - x2*z1/(r1**3*r2))/sinA - (z2*cosA/r1/r2 - z1*(cosA**2)/(r1**2))*(-x1*cosA/r1**2 + x2/(r1*r2))/(sinA**3)
print "dx2[0][1][0] =", -(3*x1*y1*cosA/r1**4 - x1*y2/(r1**3*r2) - x2*y1/(r1**3*r2))/sinA - (x2*cosA/r1/r2 - x1*(cosA**2)/(r1**2))*(-y1*cosA/r1**2 + y2/(r1*r2))/(sinA**3)
print "dx2[0][1][1] =", -(-cosA/r1**2 + 3*y1**2*cosA/r1**4 - 2*y1*y2/(r1**3*r2))/sinA - (y2*cosA/r1/r2 - y1*(cosA**2)/(r1**2))*(-y1*cosA/r1**2 + y2/(r1*r2))/(sinA**3)
print "dx2[0][1][2] =", -(3*y1*z1*cosA/r1**4 - y1*z2/(r1**3*r2) - y2*z1/(r1**3*r2))/sinA - (z2*cosA/r1/r2 - z1*(cosA**2)/(r1**2))*(-y1*cosA/r1**2 + y2/(r1*r2))/(sinA**3)
print "dx2[0][2][0] =", -(3*x1*z1*cosA/r1**4 - x1*z2/(r1**3*r2) - x2*z1/(r1**3*r2))/sinA - (x2*cosA/r1/r2 - x1*(cosA**2)/(r1**2))*(-z1*cosA/r1**2 + z2/(r1*r2))/(sinA**3)
print "dx2[0][2][1] =", -(3*y1*z1*cosA/r1**4 - y1*z2/(r1**3*r2) - y2*z1/(r1**3*r2))/sinA - (y2*cosA/r1/r2 - y1*(cosA**2)/(r1**2))*(-z1*cosA/r1**2 + z2/(r1*r2))/(sinA**3)
print "dx2[0][2][2] =", -(-cosA/r1**2 + 3*z1**2*cosA/r1**4 - 2*z1*z2/(r1**3*r2))/sinA - (z2*cosA/r1/r2 - z1*(cosA**2)/(r1**2))*(-z1*cosA/r1**2 + z2/(r1*r2))/(sinA**3)
print "dx2[1][0][0] = dx2[2][0][0] =",  -(x1*x2*cosA/(r1**2*r2**2) - x2**2/(r1*r2**3) + 1/(r1*r2) - x1**2/(r1**3*r2))/sinA - (-x1*cosA/r1**2 + x2/(r1*r2))*(x1*cosA/r1/r2 - x2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[1][0][1] = dx2[2][1][0] =",  -(x1*y2*cosA/(r1**2*r2**2) - x2*y2/(r1*r2**3) - x1*y1/(r1**3*r2))/sinA - (-x1*cosA/r1**2 + x2/(r1*r2))*(y1*cosA/r1/r2 - y2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[1][0][2] = dx2[2][2][0] =",  -(x1*z2*cosA/(r1**2*r2**2) - x2*z2/(r1*r2**3) - x1*z1/(r1**3*r2))/sinA - (z1*cosA/r1/r2 - z2*(cosA**2)/(r2**2))*(-x1*cosA/r1**2 + x2/(r1*r2))/(sinA**3)
print "dx2[1][1][0] = dx2[2][0][1] =",  -(x2*y1*cosA/(r1**2*r2**2) - x2*y2/(r1*r2**3) - x1*y1/(r1**3*r2))/sinA - (x1*cosA/r1/r2 - x2*(cosA**2)/(r2**2))*(-y1*cosA/r1**2 + y2/(r1*r2))/(sinA**3)
print "dx2[1][1][1] = dx2[2][1][1] =",  -(y1*y2*cosA/(r1**2*r2**2) - y2**2/(r1*r2**3) + 1/(r1*r2) - y1**2/(r1**3*r2))/sinA - (-y1*cosA/r1**2 + y2/(r1*r2))*(y1*cosA/r1/r2 - y2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[1][1][2] = dx2[2][2][1] =",  -(y1*z2*cosA/(r1**2*r2**2) - y2*z2/(r1*r2**3) - y1*z1/(r1**3*r2))/sinA - (z1*cosA/r1/r2 - z2*(cosA**2)/(r2**2))*(-y1*cosA/r1**2 + y2/(r1*r2))/(sinA**3)
print "dx2[1][2][0] = dx2[2][0][2] =",  -(x2*z1*cosA/(r1**2*r2**2) - x2*z2/(r1*r2**3) - x1*z1/(r1**3*r2))/sinA - (x1*cosA/r1/r2 - x2*(cosA**2)/(r2**2))*(-z1*cosA/r1**2 + z2/(r1*r2))/(sinA**3)
print "dx2[1][2][1] = dx2[2][1][2] =",  -(y2*z1*cosA/(r1**2*r2**2) - y2*z2/(r1*r2**3) - y1*z1/(r1**3*r2))/sinA - (y1*cosA/r1/r2 - y2*(cosA**2)/(r2**2))*(-z1*cosA/r1**2 + z2/(r1*r2))/(sinA**3)
print "dx2[1][2][2] = dx2[2][2][2] =",  -(z1*z2*cosA/(r1**2*r2**2) - z2**2/(r1*r2**3) + 1/(r1*r2) - z1**2/(r1**3*r2))/sinA - (z1*cosA/r1/r2 - z2*(cosA**2)/(r2**2))*(-z1*cosA/r1**2 + z2/(r1*r2))/(sinA**3)
print "dx2[3][0][0] =", -(-cosA/r2**2 + 3*x2**2*cosA/(r2**4) - 2*x1*x2/(r1*r2**3))/sinA - (-x2*cosA/r2**2 + x1/(r1*r2))*(x1*cosA/r1/r2 - x2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[3][0][1] =", -(3*x2*y2*cosA/(r2**4) - x1*y2/(r1*r2**3) - x2*y1/(r1*r2**3))/sinA - (-x2*cosA/r2**2 + x1/(r1*r2))*(y1*cosA/r1/r2 - y2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[3][0][2] =", -(3*x2*z2*cosA/(r2**4) - x1*z2/(r1*r2**3) - x2*z1/(r1*r2**3))/sinA - (-x2*cosA/r2**2 + x1/(r1*r2))*(z1*cosA/r1/r2 - z2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[3][1][0] =", -(3*x2*y2*cosA/(r2**4) - x1*y2/(r1*r2**3) - x2*y1/(r1*r2**3))/sinA - (-y2*cosA/r2**2 + y1/(r1*r2))*(x1*cosA/r1/r2 - x2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[3][1][1] =", -(-cosA/r2**2 + 3*y2**2*cosA/(r2**4) - 2*y1*y2/(r1*r2**3))/sinA - (-y2*cosA/r2**2 + y1/(r1*r2))*(y1*cosA/r1/r2 - y2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[3][1][2] =", -(3*y2*z2*cosA/(r2**4) - y1*z2/(r1*r2**3) - y2*z1/(r1*r2**3))/sinA - (-y2*cosA/r2**2 + y1/(r1*r2))*(z1*cosA/r1/r2 - z2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[3][2][0] =", -(3*x2*z2*cosA/(r2**4) - x1*z2/(r1*r2**3) - x2*z1/(r1*r2**3))/sinA - (-z2*cosA/r2**2 + z1/(r1*r2))*(x1*cosA/r1/r2 - x2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[3][2][1] =", -(3*y2*z2*cosA/(r2**4) - y1*z2/(r1*r2**3) - y2*z1/(r1*r2**3))/sinA - (-z2*cosA/r2**2 + z1/(r1*r2))*(y1*cosA/r1/r2 - y2*(cosA**2)/(r2**2))/(sinA**3)
print "dx2[3][2][2] =", -(-cosA/r2**2 + 3*z2**2*cosA/(r2**4) - 2*z1*z2/(r1*r2**3))/sinA - (-z2*cosA/r2**2 + z1/(r1*r2))*(z1*cosA/r1/r2 - z2*(cosA**2)/(r2**2))/(sinA**3)
